package com.xunwulian.cmeb.command;

import com.xunwulian.base.constant.ConstantBean;
import com.xunwulian.base.exception.ErrorCodeException;
import org.json.JSONArray;

/**
 * Created by liyankai on 2016/9/10.
 */
public class SmsUsedCommand extends Command {

    private String msisdn;

    public SmsUsedCommand(Receiver receiver, String msisdn) {
        super(APICode.SMSUSEDCURRENTMONTH, receiver);
        this.msisdn = msisdn;
    }

    @Override
    public String getParam() {
        return "msisdn=" + msisdn;
    }

    @Override
    public Integer execute() throws ErrorCodeException {
        JSONArray result = receiver.actionPost(api, getParam());

        int sms = ConstantBean.FAIL_VALUE_INT;
        if (null != result && result.length() != 0) {
            sms = result.getJSONObject(0).getInt("sms");
        }

        return sms;
    }
}
